package 极客算法训练营.chapter11;

public class 有效的完全平方数 {
    class Solution {
        public boolean isPerfectSquare(int num) {
            if (num < 2) {
                return true;
            }
            int left = 0, right = num / 2, mid, result;
            while (left <= right) {
                mid = (left + right) / 2;
                result = mid * mid;
                if (result == num) {
                    return true;
                } else if (result > num) {
                    right = mid - 1;
                } else {
                    left = mid + 1;
                }
            }
            //如果是2或3，不走while，直接false
            return false;
        }
    }
}
